import gameConfig from "../engines/configs/gameConfig";
import O1HD, { managers, modules, services } from "../engines/gameEngine";
import { CsvFileKind } from "../engines/libs/CsvFileKind";
import { GAME_MODE } from "../engines/managers/gameContent/gameMode_json";
import { REWARD_TYPE } from "../engines/services/userContent/userInterface";
import { PAGE } from "../Game/Enum";
import mainRoot from "../Game/MainRoot";

const { ccclass, property } = cc._decorator;

@ccclass
export default class hall extends cc.Component {
    public static PlatFrom: string = "";//平台信息
    onLoad() {
        // console.log('<hall> 场景', cc.sys.platform);;
        managers().soundMgr.playMusic("mainSound/bgm");
        services().miniGameSrv.getAppApiInstance().gameRecordStop();
        O1HD.getServices().userSrv.setCoins(0,false);
        // if(!O1HD.getServices().miniGameSrv.getAppApiInstance().isProduction()){
        //     O1HD.getServices().userSrv.setCoins(999,false);
        // }
        // if(O1HD.getServices().userSrv.getFirstLogin() != "1"){
        //     // 打开每日送免广告币
        //     O1HD.getServices().userSrv.setFirstLogin(1);
        //     mainRoot.UISystem.OpenPage(PAGE.DAILYBONUSPAGE);
        //     O1HD.getServices().userSrv.setLastLoginDate();
        // }
        O1HD.getManagers().goldMinerManager.resetProp();
        O1HD.getManagers().peopleArcheryManager.loadConfig();
    }

    onBtnStart(e, custom: string) {
        const mode = Number(custom);
        if (services().userSrv.getPower() - gameConfig.MODE_POWER[mode] < 0) {
            modules().uiControlModule.showUserPropGet(REWARD_TYPE.POWER, gameConfig.ADD_ONCE_POWER);
            return;
        }
        // console.log("包名");
        // console.warn('重置7');
        mainRoot.GotTips = false;
        mainRoot.GotAnswer = false;
        let bundleName: string = mainRoot.LevelSystem.GetSignleLevelInfo(mode).bundleName;
        services().userSrv.setPower(-gameConfig.MODE_POWER[mode], true, true);
        mainRoot.LevelSystem.LoadLevel(bundleName, mode);
    }

    onBtnStartLevel(e:cc.Event.EventTouch,custom:string){
        const mode = Number(custom);
        
        mainRoot.GotTips = false;
        mainRoot.GotAnswer = false;
        let levelIndex = mainRoot.LevelSystem.GetCurrLevel(mode);
        mainRoot.LevelSystem.LoadLevel(mainRoot.LevelSystem.GetSignleLevelInfo(mode, levelIndex).bundleName, mode, levelIndex);
    }

    private isClickMenu: boolean = false;
    OnBtnLevelMenu(e, custom: string) {
        if (this.isClickMenu) return;
        this.isClickMenu = true;
        managers().soundMgr.playSound("mainSound/anNiu");
        this.scheduleOnce(() => {
            this.isClickMenu = false;
        }, 1);
        const mode = Number(custom);
        switch(mode){
            case GAME_MODE.NORMAL:{
                O1HD.getManagers().peopleArcheryManager.loadConfig().then(()=>{
                    mainRoot.UISystem.OpenPage(PAGE.PEOPLE_ARCHERY_START_PAGE);
                });
                break
            }
            default:{
                let levelMenuPrams = {
                    mode: mode
                }
                mainRoot.UISystem.OpenPage(PAGE.LEVELMENU, levelMenuPrams);
                break;
            }        
        }
    }
    // OnBtnNewestLevelMenu(e, custom: string) {
    //     if (this.isClickMenu) return;
    //     this.isClickMenu = true;
    //     this.scheduleOnce(() => {
    //         this.isClickMenu = false;
    //     }, 0.2);
    //     const mode = Number(custom);
    //     let levelMenuPrams = {
    //         mode: mode
    //     }
    //     mainRoot.UISystem.OpenPage(PAGE.LEVELMENU, levelMenuPrams);
    // }

    onBtnRank(){
        managers().soundMgr.playSound('mainSound/anNiu');
        managers().soundMgr.playVibrate();
        O1HD.getServices().miniGameSrv.getAppApiInstance().showRank();
    }

    OnBtnInfinity() {
        managers().soundMgr.playSound('mainSound/anNiu');
        modules().uiControlModule.showInfinityPower(1, null);
    }
}






























